home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / fpc / compiler / script.pas < prev    next >
Pascal/Delphi Source File  |  1998-09-24  |  5KB  |  220 lines

  1. {
  2.     $Id: script.pas,v 1.1.1.1 1998/03/25 11:18:13 root Exp $
  3.     Copyright (c) 1998 by Peter Vreman
  4.  
  5.     This unit handles the writing of script files
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  ****************************************************************************
  22. }
  23. unit Script;
  24. interface
  25.  
  26. uses
  27.   CObjects;
  28.  
  29. type
  30.   PScript=^TScript;
  31.   TScript=object
  32.     fn   : string[80];
  33.     data : TStringQueue;
  34.     constructor Init(const s:string);
  35.     destructor Done;
  36.     procedure AddStart(const s:string);
  37.     procedure Add(const s:string);
  38.     Function Empty:boolean;
  39.     procedure WriteToDisk;virtual;
  40.   end;
  41.  
  42.   TAsmScript = Object (TScript)
  43.     Constructor Init (Const ScriptName : String);
  44.     Procedure AddAsmCommand (Const Command, Options,FileName : String);
  45.     Procedure AddLinkCommand (Const Command, Options, FileName : String);
  46.     Procedure AddDeleteCommand (Const FileName : String);
  47.     Procedure WriteToDisk;virtual;
  48.     end;
  49.   PAsmScript = ^TAsmScript;
  50.  
  51. { Asm response file }
  52. var
  53.   AsmRes : TAsmScript;
  54.  
  55.  
  56. implementation
  57.  
  58. uses
  59. {$ifdef linux}
  60.   linux,
  61. {$endif}
  62.   globals,systems;
  63.  
  64.  
  65. {****************************************************************************
  66.                                   TScript
  67. ****************************************************************************}
  68.  
  69. constructor TScript.Init(const s:string);
  70. begin
  71.   fn:=FixFileName(s)+source_info.scriptext;
  72.   data.Init;
  73. end;
  74.  
  75.  
  76. destructor TScript.Done;
  77. begin
  78.   data.done;
  79. end;
  80.  
  81.  
  82. procedure TScript.AddStart(const s:string);
  83. begin
  84.   data.Insert(s);
  85. end;
  86.  
  87.  
  88. procedure TScript.Add(const s:string);
  89. begin
  90.   data.Concat(s);
  91. end;
  92.  
  93.  
  94. Function TScript.Empty:boolean;
  95. begin
  96.   Empty:=Data.Empty;
  97. end;
  98.  
  99.  
  100. procedure TScript.WriteToDisk;
  101. var
  102.   t : Text;
  103. begin
  104.   Assign(t,fn);
  105.   Rewrite(t);
  106.   while not data.Empty do
  107.    Writeln(t,data.Get);
  108.   Close(t);
  109. {$ifdef linux}
  110.   ChMod(fn,493);
  111. {$endif}
  112. end;
  113.  
  114.  
  115. {****************************************************************************
  116.                                   Asm Response
  117. ****************************************************************************}
  118.  
  119. Constructor TAsmScript.Init (Const ScriptName : String);
  120.  
  121. begin
  122.   Inherited Init(ScriptName);
  123. end;
  124.  
  125. Procedure TAsmScript.AddAsmCommand (Const Command, Options,FileName : String);
  126.  
  127. begin
  128.   {$ifdef linux}
  129.   Add('echo Assembling '+FileName);
  130.   Add (Command+' '+Options);
  131.   Add('if [ $? != 0 ]; then DoExitAsm '+FileName+'; fi');
  132.   {$else}
  133.   Add('SET THEFILE='+FileName);
  134.   Add('echo Assembling %THEFILE%');
  135.   Add(command+' '+Options);
  136.   Add('if errorlevel 1 goto asmend');
  137.   {$endif}
  138. end;
  139.  
  140. Procedure TasmScript.AddLinkCommand (Const Command, Options, FileName : String);
  141.  
  142. begin
  143.   {$ifdef linux}
  144.   Add('echo Linking '+FileName);
  145.   Add (Command+' '+Options);
  146.   Add('if [ $? != 0 ]; then DoExitLink '+FileName+'; fi');
  147.   {$else}
  148.   Add('SET THEFILE='+FileName);
  149.   Add('echo Linking %THEFILE%');
  150.   Add (Command+' '+Options);
  151.   Add('if errorlevel 1 goto linkend');
  152.   {$endif}
  153. end;
  154.  
  155.  
  156.  Procedure TAsmScript.AddDeleteCommand (Const FileName : String);
  157.  
  158. begin
  159.  {$ifdef linux}
  160.  Add('rm '+FileName);
  161.  {$else}
  162.  Add('Del '+FileName);
  163.  {$endif}
  164. end;
  165.  
  166.  
  167. Procedure TAsmScript.WriteToDisk;
  168.  
  169. Begin
  170. {$ifdef linux}
  171.   AddStart('{ echo "An error occurred while linking $1"; exit 1; }');
  172.   AddStart('DoExitLink ()');
  173.   AddStart('{ echo "An error occurred while assembling $1"; exit 1; }');
  174.   AddStart('DoExitAsm ()');
  175.   AddStart('#!/bin/bash');
  176. {$else}
  177.   AddStart('@echo off');
  178.   Add('goto end');
  179.   Add(':asmend');
  180.   Add('echo An error occured while assembling %THEFILE%');
  181.   Add('goto end');
  182.   Add(':linkend');
  183.   Add('echo An error occured while linking %THEFILE%');
  184.   Add(':end');
  185. {$endif}
  186.   TScript.WriteToDisk;
  187. end;
  188.  
  189.  
  190. end.
  191. {
  192.   $Log: script.pas,v $
  193.   Revision 1.1.1.1  1998/03/25 11:18:13  root
  194.   * Restored version
  195.  
  196.   Revision 1.6  1998/03/10 01:17:28  peter
  197.     * all files have the same header
  198.     * messages are fully implemented, EXTDEBUG uses Comment()
  199.     + AG... files for the Assembler generation
  200.  
  201.   Revision 1.5  1998/02/23 12:53:46  pierre
  202.     + added some info when running ppas.bat
  203.       * updated makefile
  204.  
  205.   Revision 1.4  1998/02/19 00:11:08  peter
  206.     * fixed -g to work again
  207.     * fixed some typos with the scriptobject
  208.  
  209.   Revision 1.3  1998/02/18 14:18:30  michael
  210.   + added log at end of file (retroactively)
  211.  
  212.   revision 1.2
  213.   date: 1998/02/18 13:43:15;  author: michael;  state: Exp;  lines: +75 -20
  214.   + Implemented an OS independent AsmRes object.
  215.   ----------------------------
  216.   revision 1.1
  217.   date: 1998/02/17 21:44:04;  author: peter;  state: Exp;
  218.     + Initial implementation
  219. }
  220.